home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / op-m-cs.cc < prev    next >
C/C++ Source or Header  |  1997-01-24  |  7KB  |  250 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if defined (__GNUG__)
  24. #pragma implementation
  25. #endif
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include <config.h>
  29. #endif
  30.  
  31. #include "gripes.h"
  32. #include "ov.h"
  33. #include "ov-re-mat.h"
  34. #include "ov-cx-mat.h"
  35. #include "ov-complex.h"
  36. #include "ov-typeinfo.h"
  37. #include "op-m-cs.h"
  38. #include "ops.h"
  39. #include "xdiv.h"
  40. #include "xpow.h"
  41.  
  42. // matrix by complex scalar ops.
  43.  
  44. static octave_value
  45. add (const octave_value& a1, const octave_value& a2)
  46. {
  47.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex&);
  48.  
  49.   return octave_value (v1.matrix_value () + v2.complex_value ());
  50. }
  51.  
  52. static octave_value
  53. sub (const octave_value& a1, const octave_value& a2)
  54. {
  55.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex&);
  56.  
  57.   return octave_value (v1.matrix_value () - v2.complex_value ());
  58. }
  59.  
  60. static octave_value
  61. mul (const octave_value& a1, const octave_value& a2)
  62. {
  63.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex&);
  64.  
  65.   return octave_value (v1.matrix_value () * v2.complex_value ());
  66. }
  67.  
  68. static octave_value
  69. div (const octave_value& a1, const octave_value& a2)
  70. {
  71.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex&);
  72.  
  73.   Complex d = v2.complex_value ();
  74.  
  75.   if (d == 0.0)
  76.     gripe_divide_by_zero ();
  77.  
  78.   return octave_value (v1.matrix_value () / d);
  79. }
  80.  
  81. static octave_value
  82. pow (const octave_value& a1, const octave_value& a2)
  83. {
  84.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex&);
  85.  
  86.   return xpow (v1.matrix_value (), v2.complex_value ());
  87. }
  88.  
  89. static octave_value
  90. ldiv (const octave_value& v1, const octave_value&)
  91. {
  92.   gripe_nonconformant ("operator \\", v1.rows (), v1.columns (), 1, 1);
  93.   return octave_value ();
  94. }
  95.  
  96. #define BOOL_OP(OP, EMPTY_RESULT) \
  97.   MX_SC_BOOL_OP (Matrix, m, v1.matrix_value (), \
  98.          Complex, s, v2.complex_value (), \
  99.          m (i, j) OP real (s), EMPTY_RESULT)
  100.  
  101. static octave_value
  102. lt (const octave_value& a1, const octave_value& a2)
  103. {
  104.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex&);
  105.  
  106.   BOOL_OP (<, Matrix ());
  107. }
  108.  
  109. static octave_value
  110. le (const octave_value& a1, const octave_value& a2)
  111. {
  112.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex&);
  113.  
  114.   BOOL_OP (<=, Matrix ());
  115. }
  116.  
  117. static octave_value
  118. eq (const octave_value& a1, const octave_value& a2)
  119. {
  120.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex&);
  121.  
  122.   MX_SC_BOOL_OP (Matrix, m, v1.matrix_value (),
  123.          Complex, s, v2.complex_value (),
  124.          m (i, j) == s, 0.0);
  125. }
  126.  
  127. static octave_value
  128. ge (const octave_value& a1, const octave_value& a2)
  129. {
  130.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex&);
  131.  
  132.   BOOL_OP (>=, Matrix ());
  133. }
  134.  
  135. static octave_value
  136. gt (const octave_value& a1, const octave_value& a2)
  137. {
  138.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex&);
  139.  
  140.   BOOL_OP (>, Matrix ());
  141. }
  142.  
  143. static octave_value
  144. ne (const octave_value& a1, const octave_value& a2)
  145. {
  146.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex&);
  147.  
  148.   MX_SC_BOOL_OP (Matrix, m, v1.matrix_value (),
  149.          Complex, s, v2.complex_value (),
  150.          m (i, j) != s, 1.0);
  151. }
  152.  
  153. static octave_value
  154. el_mul (const octave_value& a1, const octave_value& a2)
  155. {
  156.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex&);
  157.  
  158.   return octave_value (v1.matrix_value () * v2.complex_value ());
  159. }
  160.  
  161. static octave_value
  162. el_div (const octave_value& a1, const octave_value& a2)
  163. {
  164.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex&);
  165.  
  166.   Complex d = v2.complex_value ();
  167.  
  168.   if (d == 0.0)
  169.     gripe_divide_by_zero ();
  170.  
  171.   return octave_value (v1.matrix_value () / d);
  172. }
  173.  
  174. static octave_value
  175. el_pow (const octave_value& a1, const octave_value& a2)
  176. {
  177.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex&);
  178.  
  179.   return elem_xpow (v1.matrix_value (), v2.complex_value ());
  180. }
  181.  
  182. static octave_value
  183. el_ldiv (const octave_value& a1, const octave_value& a2)
  184. {
  185.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex&);
  186.  
  187.   return x_el_div (v2.complex_value (), v1.matrix_value ());
  188. }
  189.  
  190. static octave_value
  191. el_and (const octave_value& a1, const octave_value& a2)
  192. {
  193.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex&);
  194.  
  195.   MX_SC_BOOL_OP (Matrix, m, v1.matrix_value (),
  196.          Complex, s, v2.complex_value (),
  197.          m (i, j) && s != 0.0, Matrix ());
  198. }
  199.  
  200. static octave_value
  201. el_or (const octave_value& a1, const octave_value& a2)
  202. {
  203.   CAST_BINOP_ARGS (const octave_matrix&, const octave_complex&);
  204.  
  205.   MX_SC_BOOL_OP (Matrix, m, v1.matrix_value (),
  206.          Complex, s, v2.complex_value (),
  207.          m (i, j) || s != 0.0, Matrix ());
  208. }
  209.  
  210. static octave_value *
  211. complex_matrix_conv (const octave_value& a)
  212. {
  213.   CAST_CONV_ARG (const octave_matrix&);
  214.  
  215.   return new octave_complex_matrix (ComplexMatrix (v.matrix_value ()));
  216. }
  217.  
  218. void
  219. install_m_cs_ops (void)
  220. {
  221.   INSTALL_BINOP (add, octave_matrix, octave_complex, add);
  222.   INSTALL_BINOP (sub, octave_matrix, octave_complex, sub);
  223.   INSTALL_BINOP (mul, octave_matrix, octave_complex, mul);
  224.   INSTALL_BINOP (div, octave_matrix, octave_complex, div);
  225.   INSTALL_BINOP (pow, octave_matrix, octave_complex, pow);
  226.   INSTALL_BINOP (ldiv, octave_matrix, octave_complex, ldiv);
  227.   INSTALL_BINOP (lt, octave_matrix, octave_complex, lt);
  228.   INSTALL_BINOP (le, octave_matrix, octave_complex, le);
  229.   INSTALL_BINOP (eq, octave_matrix, octave_complex, eq);
  230.   INSTALL_BINOP (ge, octave_matrix, octave_complex, ge);
  231.   INSTALL_BINOP (gt, octave_matrix, octave_complex, gt);
  232.   INSTALL_BINOP (ne, octave_matrix, octave_complex, ne);
  233.   INSTALL_BINOP (el_mul, octave_matrix, octave_complex, el_mul);
  234.   INSTALL_BINOP (el_div, octave_matrix, octave_complex, el_div);
  235.   INSTALL_BINOP (el_pow, octave_matrix, octave_complex, el_pow);
  236.   INSTALL_BINOP (el_ldiv, octave_matrix, octave_complex, el_ldiv);
  237.   INSTALL_BINOP (el_and, octave_matrix, octave_complex, el_and);
  238.   INSTALL_BINOP (el_or, octave_matrix, octave_complex, el_or);
  239.  
  240.   INSTALL_ASSIGNCONV (octave_matrix, octave_complex, octave_complex_matrix);
  241.  
  242.   INSTALL_WIDENOP (octave_matrix, octave_complex_matrix, complex_matrix_conv);
  243. }
  244.  
  245. /*
  246. ;;; Local Variables: ***
  247. ;;; mode: C++ ***
  248. ;;; End: ***
  249. */
  250.